package com.szd.qiongyou20.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.szd.qiongyou20.R;
import com.szd.qiongyou20.home.adapter.GridView_City_Adapter;
import com.szd.qiongyou20.home.adapter.GridView_City_Out_Adapter;
import com.szd.qiongyou20.home.adapter.RecyclerView_City_Play_Adapetr;
import com.szd.qiongyou20.home.adapter.RecyclerView_City_ReadMore_Adapetr;
import com.szd.qiongyou20.home.adapter.ViewPager_City_Adapter;
import com.szd.qiongyou20.home.adapter.ViewPager_City_Special_Adapter;
import com.szd.qiongyou20.home.bean.CityData;
import com.szd.qiongyou20.home.presenter.CityPre;
import com.szd.qiongyou20.home.view.CityDataToView;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class CityActivity extends AppCompatActivity implements CityDataToView {

    @Bind(R.id.viewpager_city)
    ViewPager mViewpagerCity;
    @Bind(R.id.imageView_back_city)
    ImageView mImageViewBackCity;
    @Bind(R.id.textView_name)
    TextView mTextViewName;
    @Bind(R.id.textView_EnName)
    TextView mTextViewEnName;
    @Bind(R.id.textView_city_name)
    TextView mTextViewCityName;
    @Bind(R.id.textView_city_EnName)
    TextView mTextViewCityEnName;
    @Bind(R.id.textView_weather)
    TextView mTextViewWeather;
    @Bind(R.id.textView_jn_name)
    TextView mTextViewJnName;
    @Bind(R.id.textView_jn_count)
    TextView mTextViewJnCount;
    @Bind(R.id.layout_Jn)
    LinearLayout mLayoutJn;
    @Bind(R.id.viewPager_city_type)
    ViewPager mViewPagerCityType;
    @Bind(R.id.imageView_city_map)
    ImageView mImageViewCityMap;
    @Bind(R.id.textView_city_map)
    TextView mTextViewCityMap;
    @Bind(R.id.imageView_city_enshrine)
    ImageView mImageViewCityEnshrine;
    @Bind(R.id.textView_look_destination)
    TextView mTextViewLookDestination;
    @Bind(R.id.textView_not_miss)
    TextView mTextViewNotMiss;
    @Bind(R.id.imageView_city_top1)
    ImageView mImageViewCityTop1;
    @Bind(R.id.textView_city_top01)
    TextView mTextViewCityTop01;
    @Bind(R.id.imageView_city_top2)
    ImageView mImageViewCityTop2;
    @Bind(R.id.textView_city_top02)
    TextView mTextViewCityTop02;
    @Bind(R.id.gridView_city_scenic)
    GridView mGridViewCityScenic;
    @Bind(R.id.textView_city_all)
    TextView mTextViewCityAll;
    @Bind(R.id.textView_city_specialty)
    TextView mTextViewCitySpecialty;
    @Bind(R.id.tabLayout_city)
    TabLayout mTabLayoutCity;
    @Bind(R.id.viewPager_city_specialty)
    ViewPager mViewPagerCitySpecialty;
    @Bind(R.id.textView_city_play)
    TextView mTextViewCityPlay;
    @Bind(R.id.recyclerView_city)
    RecyclerView mRecyclerViewCity;
    @Bind(R.id.textView_city_out_must)
    TextView mTextViewCityOutMust;
    @Bind(R.id.gridView_city_out_must)
    GridView mGridViewCityOutMust;
    @Bind(R.id.textView_city_read_more)
    TextView mTextViewCityReadMore;
    @Bind(R.id.textView_city_hotel)
    TextView mTextViewCityHotel;
    @Bind(R.id.textView_city_hotel_details)
    TextView mTextViewCityHotelDetails;
    @Bind(R.id.imageView_)
    ImageView mImageView;
    @Bind(R.id.textView_look_all)
    TextView mTextViewLookAll;
    @Bind(R.id.recyclerView_city_read_more)
    RecyclerView mRecyclerViewCityReadMore;

    private Context mContext = this;

    private CityPre mCityPre;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ctivy);
        ButterKnife.bind(this);

        // 创建intent对象
        Intent intent = getIntent();
        // 取出intent携带的数据
        int id = intent.getIntExtra("city_id", 0);
        // 拼接成中间人需要串参数的字符串
        String city_id = id + "";
        Log.i("城市的id", "onCreate: " + city_id);

        mCityPre = new CityPre(this, city_id);
        mCityPre.loadDataToView(mContext);
    }

    @Override
    public void toView(CityData cityData) {
        List<String> city_pic = cityData.getData().getCity_pic();

        // 设置ViewPager
        ViewPager_City_Adapter viewPager_city_adapter = new ViewPager_City_Adapter(mContext, city_pic);
        mViewpagerCity.setAdapter(viewPager_city_adapter);

        // 设置toolbar
        // 设置返回箭头的点击事件
        mImageViewBackCity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });

        //
        String cnname = cityData.getData().getCnname();
        String enname = cityData.getData().getEnname();

        mTextViewName.setText(cnname);
        mTextViewEnName.setText(enname);

        mTextViewCityName.setText(cnname);
        mTextViewCityEnName.setText(enname);

        // 天气及温度

        String info = cityData.getData().getWeather().getInfo();
        String low_temp = cityData.getData().getWeather().getLow_temp();
        String high_temp = cityData.getData().getWeather().getHigh_temp();

        mTextViewWeather.setText(info + " " + low_temp + "~" + high_temp);

        // 锦囊条
        int guide_num = cityData.getData().getGuide_num();
        mTextViewJnName.setText(cnname + "锦囊");
        mTextViewJnCount.setText("全部" + guide_num + "本");

        // 分类


        // 地图图片
        String city_map = cityData.getData().getCity_map();
        Glide.with(mContext).load(city_map).into(mImageViewCityMap);
        mTextViewCityMap.setText(cnname + "地图");

        // 收藏的XX
        mTextViewLookDestination.setText("我收藏的" + cnname + "目的地");

        // top必去
        List<CityData.DataBean.NotMissBean.EventsBean> events =
                cityData.getData().getNot_miss().getEvents();

        int id = events.get(0).getId();
        String icon = events.get(0).getIcon();
        String name = events.get(0).getName();
        String photo = events.get(0).getPhoto();
        String url = events.get(0).getUrl();

        Glide.with(mContext).load(photo).into(mImageViewCityTop1);
        mTextViewCityTop01.setText(name);

        int id1 = events.get(1).getId();
        String icon1 = events.get(1).getIcon();
        String name1 = events.get(1).getName();
        String photo1 = events.get(1).getPhoto();
        String url1 = events.get(1).getUrl();

        Glide.with(mContext).load(photo1).into(mImageViewCityTop2);
        mTextViewCityTop02.setText(name1);

        // 必去之6个点
        List<CityData.DataBean.NotMissBean.PoisBean> pois =
                cityData.getData().getNot_miss().getPois();
        GridView_City_Adapter gridView_city_adapter = new GridView_City_Adapter(mContext, pois);
        mGridViewCityScenic.setFocusable(false);
        mGridViewCityScenic.setAdapter(gridView_city_adapter);

        // 特色XX
        mTextViewCitySpecialty.setText("特色" + cnname);
        List<CityData.DataBean.CityRecommendTagBean> city_recommend_tag =
                cityData.getData().getCity_recommend_tag();

        // 设置特特色的ViewPager的适配器
        ViewPager_City_Special_Adapter viewPager_city_special_adapter =
                new ViewPager_City_Special_Adapter(mContext, city_recommend_tag);
        mViewPagerCitySpecialty.setAdapter(viewPager_city_special_adapter);
        // 绑定Tab标题
        mTabLayoutCity.setupWithViewPager(mViewPagerCitySpecialty);


        // 添加数据到东京住宿
        CityData.DataBean.HotelBean hotel = cityData.getData().getHotel();
        String hotel_title = hotel.getHotel_title();
        String hotel_description = hotel.getHotel_description();
        mTextViewCityHotel.setText(hotel_title);
        mTextViewCityHotelDetails.setText(hotel_description);


        // 添加数据到 推荐玩法
        // 获取数据
        List<CityData.DataBean.RecommendDiscountBean> recommend_discount =
                cityData.getData().getRecommend_discount();
        //创建recyclerView的布局管理器
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        //设置布局管理器的方向为横向
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        mRecyclerViewCity.setLayoutManager(linearLayoutManager);
        RecyclerView_City_Play_Adapetr recyclerView_city_play_adapetr =
                new RecyclerView_City_Play_Adapetr(mContext, recommend_discount);
        mRecyclerViewCity.setAdapter(recyclerView_city_play_adapetr);

        // 出行必备
        List<CityData.DataBean.TravelNecessaryBean> travel_necessary =
                cityData.getData().getTravel_necessary();
        GridView_City_Out_Adapter gridView_city_out_adapter =
                new GridView_City_Out_Adapter(mContext, travel_necessary);
        mGridViewCityOutMust.setFocusable(false);
        mGridViewCityOutMust.setAdapter(gridView_city_out_adapter);

        // 阅读更多
        // 数据源
        List<CityData.DataBean.MguideListsBean> mguide_lists =
                cityData.getData().getMguide_lists();
        // 布局管理器
        LinearLayoutManager linearLayoutManager_more =
                new LinearLayoutManager(mContext);
        // 适配器
        RecyclerView_City_ReadMore_Adapetr recyclerView_city_readMore_adapetr =
                new RecyclerView_City_ReadMore_Adapetr(mContext, mguide_lists);
        // 给RecyclerView设置
        mRecyclerViewCityReadMore.setLayoutManager(linearLayoutManager_more);
        mRecyclerViewCityReadMore.setAdapter(recyclerView_city_readMore_adapetr);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }
}
